/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package twbb;

import org.apache.log4j.Logger;


import edu.cuny.cat.*;
import edu.cuny.cat.core.Shout;
import edu.cuny.cat.event.*;
import edu.cuny.util.ParameterDatabase;
import edu.cuny.util.Utils;
import java.net.URL;
import java.util.*;

import twbb.utility.Copyright;

import twbb.adaptive.FilterMain;
import twbb.adaptive.KnowledgeAdaptive;

/**
 *
 * @author sun
 */
public class AdaptiveStrategies extends MarketClient{



    public AdaptiveStrategies() {
        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println(Copyright.getCopyright());
        System.out.println(Game.getBanner());

        try
        {
            URL url = ParameterDatabase.getURL(Game.getParameterFile(args));
            if(url == null)
                Utils.fatalError((new StringBuilder("Failed to load parameter database: ")).append(Game.getParameterFile(args)).toString());
            Game.setupPreferences(url, args);
            Collection<MarketClient> markets = Game.createMarkets();
            Game.startMarkets(markets);
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
            //logger.error(e);
        }
        
    }

    @Override
	public synchronized void eventOccurred(AuctionEvent event) {
		super.eventOccurred(event);

        if (event instanceof ShoutPlacedEvent) {
			processShoutPlaced((ShoutPlacedEvent) event);
		} else if (event instanceof TransactionExecutedEvent) {
			processTransactionExecuted((TransactionExecutedEvent) event);
		} else if (event instanceof FeesAnnouncedEvent) {
			processFeesAnnounced((FeesAnnouncedEvent) event);
		} else if (event instanceof PrivateValueAssignedEvent) {
			processPrivateValueAssigned((PrivateValueAssignedEvent) event);
		} else if (event instanceof RegistrationEvent) {
			processRegistration((RegistrationEvent) event);
		} else if (event instanceof GameStartingEvent) {
			processGameStarting((GameStartingEvent) event);
		} else if (event instanceof DayOpeningEvent) {
			processDayOpening((DayOpeningEvent) event);
		} else if (event instanceof DayOpenedEvent) {
			processDayOpened((DayOpenedEvent) event);
		} else if (event instanceof DayClosedEvent) {
			processDayClosed((DayClosedEvent) event);
		} else if (event instanceof RoundOpenedEvent) {
			processRoundOpened((RoundOpenedEvent) event);
		} else if (event instanceof RoundClosingEvent) {
			processRoundClosing((RoundClosingEvent) event);
		} else if (event instanceof RoundClosedEvent) {
			processRoundClosed((RoundClosedEvent) event);
		} else if (event instanceof ShoutReceivedEvent) {
			processShoutReceived((ShoutReceivedEvent) event);
		} else if (event instanceof DayStatPassEvent) {
			processDayStatPass((DayStatPassEvent) event);
		} else if (event instanceof DayInitPassEvent) {
			processDayInitPass((DayInitPassEvent) event);
		}

    }

    protected void processDayStatPass(DayStatPassEvent event) {
	}

	protected void processDayInitPass(DayInitPassEvent event) {
	}

	protected void processRoundClosing(RoundClosingEvent event) {
	}

	protected void processRoundClosed(RoundClosedEvent event) {
	}

	protected void processRoundOpened(RoundOpenedEvent event) {
	}

	protected void processDayClosed(DayClosedEvent event) {
	}

	protected void processDayOpening(DayOpeningEvent event) {
        dayPeriod = knowledgeAdaptive.nowDayAtPeriod();
            if(dayPeriod.equals("beginning")){

            }else if(dayPeriod.equals("final")){

            }else if(dayPeriod.equals("general")){

            }
	}

	protected void processDayOpened(DayOpenedEvent event) {
	}

	protected void processGameStarting(GameStartingEvent event) {
	}

	protected void processRegistration(RegistrationEvent event) {
        RegistrationEvent reg = (RegistrationEvent)event;
        //logger.info(e.getTraderId());
        if(reg.getTraderId().substring(0, 3).equals("buy") || reg.getTraderId().substring(0, 3).equals("Buy")){
            
        }else if(reg.getTraderId().substring(0, 3).equals("sel") || reg.getTraderId().substring(0, 3).equals("Sel")){
            
        }
	}

	protected void processPrivateValueAssigned(PrivateValueAssignedEvent event) {
	}

	protected void processFeesAnnounced(FeesAnnouncedEvent event) {
	}

	protected void processTransactionExecuted(TransactionExecutedEvent event) {
	}

	protected void processShoutPlaced(ShoutPlacedEvent event) {
	}

	protected void processShoutReceived(ShoutReceivedEvent event) {
        Shout shout = event.getShout();
		String traderId = shout.getTrader().getId();

        int shoutDay = event.getDay();
		int shoutRound = event.getRound();
        double price = shout.getPrice();
		boolean isBid = shout.isBid();
		int quantity = shout.getQuantity();

        logger.info(price);
	}



    static Logger logger = Logger.getLogger(AdaptiveStrategies.class);

    private List myMSHistory; // twbb marketshare score
    private List myProfitHistory; // twbb profit score
    private List myTSRHistory; // twbb transaction successed rate score

    private List competitorMSHistory; // Competitor marketshare score
    private List competitorProfitHistory; // Competitor profit score
    private List competitorTSRHistory; // Competitor transaction successed rate score

    FilterMain filter;
    KnowledgeAdaptive knowledgeAdaptive;
    protected String dayPeriod = "beginning";

    private int specialistsCount;
    HashMap specialistFees = new HashMap();
   


}
